require 'esi/handler'

module ESI

  class Dispatcher < ESI::Handler
    attr_reader :config, :router

    Thread.abort_on_exception = false

    def initialize( options )
      super()
      @config = ESI::Config.new( options )
      @router = nil
      if @config.start_invalidator?
        ESI::Invalidator.start( self )
      end
    end

    def process(request, response)
      @router = @config.router
      super
    end

  end
end
